package com.taxigang.client.uibinder.fbpage;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.TaxiGangHandler;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.micro.TaxiGangText;
import com.taxigang.shared.AmbassadorResponseInfo;

public class Welcome extends Composite  {

	private static WelcomeUiBinder uiBinder = GWT.create(WelcomeUiBinder.class);

	interface WelcomeUiBinder extends UiBinder<Widget, Welcome> {
	}

	//	@UiField
	//	DivElement fbLoginButton;

	@UiField
	Label welcomeTextNotLiked;
	@UiField
	Label welcomeTextNotLiked1;

//	@UiField
//	DivElement fbShareButton;
	@UiField
	Panel welcomePanelLiked;
	@UiField
	Panel welcomePanelNotLiked;
	@UiField
	Label taxigangInfo1;
	@UiField
	Label taxigangInfo2;
	@UiField
	Label taxigangInfo3;
	@UiField
	Label taxigangInfo4;

	@UiField MenuItem menuItemWelcome;
	@UiField MenuItem menuItemAmbassador;
	@UiField Panel welcomePanelContent;
	@UiField Panel ambassadorPanelContent;
	
	@UiField
	Label ambassadorText1;
	@UiField
	Label ambassadorText2;
	@UiField
	Label ambassadorText3;
	@UiField
	Label ambassadorText4;
	@UiField
	Label ambassadorText5;
	@UiField
	Label ambassadorText6;
	@UiField
	Label ambassadorText7;

	@UiField
	Button gotoTaxigang;

	@UiField
	Label thankYouLabel;

	Grid grid = new Grid(7, 2);
	Label nameLabel = new Label("Name:");
	TextBox nameBox = new TextBox();
	Label emailLabel = new Label("Email:");
	TextBox emailBox = new TextBox();
	Label phoneLabel = new Label("Handy:");
	TextBox phoneBox = new TextBox();
	Label birthdayLabel = new Label("Geburtstag:");
	TextBox birthdayBox = new TextBox();
	Label placeLabel = new Label("Wohnort:");
	TextBox placeBox = new TextBox();

	Button button = new Button("Submit");

	public Welcome(String pageId, boolean liked) {
		initWidget(uiBinder.createAndBindUi(this));
		//pageId="174406889328525";
//		fbShareButton.setAttribute("data-href", "www.facebook.com/"+pageId);
		//		fbLoginButton.setInnerHTML("<fb:login-button/>");

		welcomePanelNotLiked.setVisible(!liked);
		welcomePanelLiked.setVisible(liked);

//		welcomeTextLiked.setText(TaxiGangText.taxiGangConstants.welcomeLiked());
//		welcomeText.setText(TaxiGangText.taxiGangConstants.welcomeNotYetLiked());
		
		taxigangInfo1.setText(TaxiGangText.taxiGangConstants.taxigangInfo1());
		taxigangInfo2.setText(TaxiGangText.taxiGangConstants.taxigangInfo2());
		taxigangInfo3.setText(TaxiGangText.taxiGangConstants.taxigangInfo3());
		taxigangInfo4.setText(TaxiGangText.taxiGangConstants.taxigangInfo4());

		gotoTaxigang.setText(TaxiGangText.taxiGangConstants.startTaxigang());
		gotoTaxigang.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				//assignTop("http://www.taxigang.com");
				String href = Window.Location.getHref();
				href = href.replace("mode=FB_PAGE&", "");
				breakOut1(href);
				Window.Location.assign("http://www.taxigang.com"); 

			}
		});
		
		//ambassador
		ambassadorText1.setText(TaxiGangCreator.taxiGangConstants.ambassadorText1());
		ambassadorText2.setText(TaxiGangCreator.taxiGangConstants.ambassadorText2());
		ambassadorText3.setText(TaxiGangCreator.taxiGangConstants.ambassadorText3());
		ambassadorText4.setText(TaxiGangCreator.taxiGangConstants.ambassadorText4());
		ambassadorText5.setText(TaxiGangCreator.taxiGangConstants.ambassadorText5());
		ambassadorText6.setText(TaxiGangCreator.taxiGangConstants.ambassadorText6());
		ambassadorText7.setText(TaxiGangCreator.taxiGangConstants.ambassadorText7());
		thankYouLabel.setText(TaxiGangCreator.taxiGangConstants.ambassadorThankyou());
		
		thankYouLabel.setVisible(false);
		welcomeTextNotLiked.setText(TaxiGangCreator.taxiGangConstants.welcomeNotYetLiked());
		welcomeTextNotLiked1.setText(TaxiGangCreator.taxiGangConstants.welcomeNotYetLiked1());
		
		grid.setWidget(0, 0, nameLabel);
		grid.setWidget(0, 1, nameBox);
		grid.setWidget(1, 0, emailLabel);
		grid.setWidget(1, 1, emailBox);
		grid.setWidget(2, 0, phoneLabel);
		grid.setWidget(2, 1, phoneBox);
		grid.setWidget(3, 0, phoneLabel);
		grid.setWidget(3, 1, phoneBox);
		grid.setWidget(4, 0, placeLabel);
		grid.setWidget(4, 1, placeBox);
		
		grid.setWidget(6, 1, button);

		ambassadorPanelContent.add(grid);

		ambassadorPanelContent.setVisible(false);
		thankYouLabel.setVisible(false);

		button.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				AmbassadorResponseInfo info = new AmbassadorResponseInfo();
				info.name = nameBox.getText();
				info.email = emailBox.getText();
				info.handy = phoneBox.getText();
				info.place = placeBox.getText();
				TaxiGangHandler.getInstance().sendAmbassadorResponse(info);

				thankYouLabel.setVisible(true);
				ambassadorText7.setVisible(false);
				grid.setVisible(false);

			}
		});

		//menus
		menuItemWelcome.setCommand(new Command() {

			@Override
			public void execute() {
				welcomePanelContent.setVisible(true);
				ambassadorPanelContent.setVisible(false);
			}
			
		});
		
		menuItemAmbassador.setCommand(new Command() {

			@Override
			public void execute() {
				welcomePanelContent.setVisible(false);
				ambassadorPanelContent.setVisible(true);
				
			}
			
		});
	}

	public native void breakOut() /*-{
    if ($wnd.top.location != $wnd.location) {
        $wnd.top.location = $wnd.location.href;
    }
	}-*/;
	public native void breakOut1(String href) /*-{
    if ($wnd.top.location != $wnd.location) {
        $wnd.top.location = href;
    }
	}-*/;
	
	
	
	public static native void assignTop(String newURL) /*-{
    	$wnd.top.location.assign(newUrl);
	}-*/;
}
